package com.bj.jiufu.base;

import org.apache.log4j.Logger;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * Created by susen-pc on 2016/9/2.
 */
public class BaseService {

    private static Logger logger = Logger.getLogger(BaseService.class);

    /**
     * 异常返回
     *
     * @param e
     * @return
     */
    public static RespParam setErrorMsg(Exception e) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事务回滚
        e.printStackTrace();
        logger.error(e.getMessage());
        return setErrorMsg(e.getMessage());
    }

    /**
     * 异常返回
     *
     * @param errorMsg
     * @return
     */
    public static RespParam setErrorMsg(String errorMsg) {
        RespParam resp = new RespParam();
        logger.error(errorMsg);
        resp.setErrorMsg(errorMsg);
        return resp;
    }

    /**
     * 正常返回
     *
     * @param retData
     * @return
     */
    public static RespParam setRetData(Object retData) {
        RespParam resp = new RespParam();
        resp.setRetData(retData);
        return resp;
    }

    public static RespParam setSuccess() {
        logger.debug("======== success");
        RespParam resp = new RespParam();
        resp.setSuccess(true);
        return resp;
    }

}
